package com.whh.starter.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.EnvironmentAware;
import org.springframework.core.env.Environment;

public class SpringContextUtil implements ApplicationContextAware, EnvironmentAware {

    private static ApplicationContext context;
    private static Environment env;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }

    @Override
    public void setEnvironment(Environment environment) {
        env = environment;
    }

    public static String getProperty(String name) {
        return env.getProperty(name);
    }

    public static <T> T getProperty(String name,Class<T> tClass) {
        return env.getProperty(name,tClass);
    }


    public static <T> T getBean(String name,Class<T> tClass) {
        return context.getBean(name,tClass);
    }



}
